package net.lzzy.demoviewlocaldata.controller;

import net.lzzy.demoviewlocaldata.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class TestController {
    @GetMapping("index")
    public String getIndex(Model model) {
        // 一个对象
        User user1 = new User("dongdong",5,"一个热爱鸡蛋灌饼的小孩");

        // 一个字符串列表
        List<String> userList = new ArrayList<>();
        userList.add("zhang san 66");
        userList.add("li si 66");
        userList.add("wang wu 66");

        // 一个哈希表
        Map<String, String> map = new HashMap<>();
        map.put("place","社湾");
        map.put("feeling", "very well");

        // 数据添加到model中
        // 普通字符串
        model.addAttribute("name", "dongdong");
        //存储javabean-对象
        model.addAttribute("user", user1);
        //存储字符串List
        model.addAttribute("userList", userList);
        // 存储Map
        model.addAttribute("map", map);

        return "index";
    }
}
